package cn.com.hfuu.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.hfuu.UUIdUtil;
import cn.com.hfuu.dao.roleMapper;
import cn.com.hfuu.dao.userroleMapper;
import cn.com.hfuu.module.role;
import cn.com.hfuu.module.userrole;

@Service("userroleService")
public class UserroleService {

	@Autowired
	userroleMapper userrolemap;
	
	@Autowired
	roleMapper rolemapper;
	
	/**
	 * 根据用户获取权限组
	 * @param userid
	 * @return
	 */
	public List<role> selectbyuser(String userid){
		List<userrole> list= userrolemap.selectbyuserid(userid);
		List<role> rolelist = new ArrayList<role>();
		for (userrole userrole : list) {
			role r=rolemapper.selectByPrimaryKey(userrole.getRoleId());
			System.out.println(r.toString());
			if(r!=null){
				rolelist.add(r);
			}
			
		}
		return rolelist;
	}

	public void inserts(List<role> rolelist, String id2) {
		// TODO Auto-generated method stub
		UUIdUtil id=new UUIdUtil();
		for (role role : rolelist) {
			userrole ur=new userrole();
			ur.setRoleId(role.getRoleId());
			ur.setUserRoleId(id.getUuid());
			ur.setUserId(id2);
			userrolemap.insert(ur);
		}
	}

	public void deletes(List<role> rolemenulist1, String id) {
		// TODO Auto-generated method stub
		for (role role : rolemenulist1) {
			userrolemap.delete(role.getRoleId(),id);
		}
		
	}

	public int deleterolid(String[] ids) {
		// TODO Auto-generated method stub
		return userrolemap.deleteroleid(ids);
	}

	public int deleteuserid(String[] ids) {
		// TODO Auto-generated method stub
		return userrolemap.deleteuserid(ids);
	}
}
